// pages/login/login.js

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loginurl: app.data.url + '/zhongxue/maoapi/sign_in',
    phones:'',
    pwd:'',
    src:app.data.url +"/uploads/zhongxue/damao.png",
    username:app.data.url +"/uploads/zhongxue/shouji.png",
    password: app.data.url +"/uploads/zhongxue/passwords.png",
    loginbag:app.data.url +"/uploads/zhongxue/loginbag.png",
  },

  wangjimima:function(){
    wx.navigateTo({
      url: '/pages/wangjimima/wangjimima',
    })
  },

  rigister:function(){
  wx.navigateTo({
    url: '/pages/register/register',
  })
  },
  

  bindKeyInput:function(event){
   var phone=event.detail.value;
  var s=this
   this.setData({
  phones:phone
   })
  },
  
  bindKeyInputs: function (event) {
    var password = event.detail.value;
    var s = this
    this.setData({
      pwd: password
    })
  },

  
   login:function(e){
     var phones = this.data.phones;
     var  pwd=this.data.pwd;
     wx.request({
       url: this.data.loginurl,
       data:{phones:this.data.phones,pwd:this.data.pwd},
       method:'post',
       success:function(res){
       var ress=res.data;
      //  console.log(ress);
        if(ress.code==200){
          console.log(ress.data)
         wx.setStorageSync("user", ress.data);
         wx.showToast({
           title: '登录成功',
           icon:'none',
           duration: app.data.quanbushijian
         })
          var  ss = getCurrentPages();
          for(var a=0;a<ss.length;a++){
            console.log(ss[a].route)
          }
          setTimeout(function(){
            wx.switchTab({
              url: '/pages/my/my',
            })
          },1000)


        
        }else{
        var  res=res.data.msg;

           wx.showToast({
             title: ''+res+'',
             icon:"none",
             duration: app.data.quanbushijian
           })
        }
       
       }

     })

   },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: '/pages/indexfirst/indexfirst',
    }
  }
})